"""
对yaml文件的操作
extract.yaml:用来保存公共的中间变量
"""
import os

import yaml

from config import setting


#读取
def read_yaml(key):
    with open(setting.extract_name, encoding='utf-8') as f:
        value = yaml.safe_load(f)
        return value[key]

#读取extract.yaml里面所有的值
def read_all():
    with open(setting.extract_name, encoding='utf-8') as f:
        value = yaml.safe_load(f)
        return value

#写入
def write_yaml(data):
    with open(setting.extract_name, encoding='utf-8', mode="a") as f:
        yaml.safe_dump(data, f, allow_unicode=True)

#清空：写入 但不写入任何内容 就等于清空
def clean_yaml():
    with open(setting.extract_name, encoding='utf-8', mode="w") as f:
        pass

